﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace com.demo
{
    // TypeConverter指定用作此属性所绑定到的对象的转换器的类型。
[System.ComponentModel.TypeConverter(typeof(ExpandableObjectConverter))]
[System.ComponentModel.Editor( typeof( UploadProgressEditor), typeof( System.Drawing.Design.UITypeEditor))]
public class UploadProgress : System.Web.UI.IStateManager
{
    private int dueTime;
    private int period;
    private bool enabled;
    private string callbackFunc;
    private string guid = System.Guid.NewGuid().ToString();

    // 一定要设置 NotifyParentProperty 标签
    [NotifyParentProperty(true)]
    public int DueTime
    {
        get { return this.dueTime; }
        set { this.dueTime = value; }
    }

    [NotifyParentProperty(true)]
    public int Period
    {
        get { return this.period; }
        set { this.period = value; }
    }

    [NotifyParentProperty(true)]
    public bool Enabled
    {
        get { return this.enabled; }
        set { this.enabled = value; }
    }

    [NotifyParentProperty(true)]
    public string CallbackFunc
    {
        get { return this.callbackFunc; }
        set { this.callbackFunc = value; }
    }

    public string Guid
    {
        get { return this.guid; }
    }

    public override string ToString()
    {
        return string.Empty;
    }

    #region IStateManager Members

    private bool isTrackingViewState;
    public bool IsTrackingViewState
    {
        get { return this.isTrackingViewState; }
    }

    public void LoadViewState(object state)
    {
        System.Web.UI.Triplet triplet = state
            as System.Web.UI.Triplet;

        if (triplet != null)
        {
            this.callbackFunc = triplet.First as string;
            this.enabled = (bool) triplet.Second;

            System.Web.UI.Triplet t = triplet.Third
                as System.Web.UI.Triplet;
            if (t != null)
            {
                this.dueTime = (int) t.First;
                this.period = (int) t.Second;
                this.guid = t.Third as string;
            }
        }
    }

    public object SaveViewState()
    {
        System.Web.UI.Triplet t = new System.Web.UI.Triplet();
        t.First = this.dueTime;
        t.Second = this.period;
        t.Third = this.guid;

        System.Web.UI.Triplet triplet = new System.Web.UI.Triplet();
        triplet.First = this.callbackFunc;
        triplet.Second = this.enabled;
        triplet.Third = t;

        return triplet;
    }

    public void TrackViewState()
    {
        this.isTrackingViewState = true;
    }

    #endregion
}
}
